#include <libguile.h>

#include "utils.h"

static SCM termit_main()
{
    gtk_main();
    return SCM_UNSPECIFIED;
}

static SCM termit_print_tab_num(SCM s_tabNum)
{
    TRACE_MSG(__FUNCTION__);
    SCM_ASSERT(scm_is_number(s_tabNum), s_tabNum, SCM_ARG1, "termit-print-tab-num"); 
    int tabnum = 0;
    tabnum = scm_num2dbl(s_tabNum, "termit");

    TRACE("%d", tabnum);
    return SCM_UNSPECIFIED;
}

static SCM termit_print_tab_name(SCM s_tabName)
{
    TRACE_MSG(__FUNCTION__);
    SCM_ASSERT(scm_string_p(s_tabName), s_tabName, SCM_ARG1, "termit-print-tab-name"); 
    gchar* tabName = scm_to_locale_string(s_tabName);

    TRACE("%s", tabName);
    return SCM_UNSPECIFIED;
}

void termit_guile_after_tab_open(gint n)
{
    TRACE("%s(%d)", __FUNCTION__, n);
    scm_c_eval_string("(after-tab-open 2)");
}

void register_procs()
{
    TRACE_MSG(__FUNCTION__);
    scm_c_define_gsubr("termit-main", 0, 0, 0, termit_main);
    scm_c_define_gsubr("termit-print-tab-num", 1, 0, 0, termit_print_tab_num);
    scm_c_define_gsubr("termit-print-tab-name", 1, 0, 0, termit_print_tab_name);
}

static void termit_guile_main(void* closure, int ac, char** av)
{
    TRACE_MSG(__FUNCTION__);
    register_procs();
    scm_c_primitive_load("termit.scm");
    scm_c_eval_string("(termit-main)");
}

void termit_init_guile(int ac, char** av)
{
    TRACE_MSG(__FUNCTION__);
    scm_boot_guile(ac, av, termit_guile_main, 0);
}

